package com.xiaode.controller.app.myCampus.share;

import com.jfinal.aop.Inject;
import com.jfinal.core.Controller;
import com.jfinal.core.Path;
import com.jfinal.ext.cors.EnableCORS;
import com.jfinal.kit.Ret;
import com.xiaode.common.anotation.BooleanV;
import com.xiaode.common.anotation.JSONArrayString;
import com.xiaode.util.apidoc.annotation.Api;
import com.xiaode.util.apidoc.annotation.ApiOper;
import com.xiaode.util.apidoc.annotation.ApiPara;
import javax.validation.constraints.Size;

@Path("/share")
@Api("发布模块(目前是教师推荐和原创发布相关的)")
@EnableCORS
public class ShareController extends Controller {
	
    @Inject
    ShareService service;


    
    @ApiOper("查询教师推荐详情")
    public void findRecommendDetails(@Size @ApiPara(value = "recommendId",notes = "推荐id")Integer recommendId)throws Exception{
    	Integer accountId = getAttr("accountId");
    	Integer userTypeMy = getAttr("userType");
        Ret ret = service.findRecommendDetails(accountId, userTypeMy, recommendId);
        renderJson(ret);
    }
    
    @ApiOper("查询原创发布详情")
    public void findOriginalDetails(@Size @ApiPara(value = "originalId",notes = "原创d")Integer originalId)throws Exception{
    	Integer accountId = getAttr("accountId");
    	Integer userTypeMy = getAttr("userType");
        Ret ret = service.findOriginalDetails(accountId, userTypeMy, originalId);
        renderJson(ret);
    }
    
    @ApiOper("查询原创发布详情(仅在原创发布来自活动任务时调用)")
    public void findCampusOriginalInfo(@ApiPara(value = "campusId", notes = "原创发布Id") Integer campusId) throws Exception {
    	Integer accountId = getAttr("accountId");
        Ret ret = service.findCampusOriginalInfo(accountId, campusId);
        renderJson(ret);
    }
    
    
    
    
    @ApiOper("查询原创发布列表")
    public void findCampusOriginalByPage(
    		@ApiPara(value = "createAccountId", notes = "创建人Id(用于个人详情页，查看这个人的发布)") Integer createAccountId,
    		@Size @ApiPara(value = "page", notes = "当前页") Integer page,
    		@Size @ApiPara(value = "limit", notes = "每页大小") Integer limit) throws Exception {
        Integer accountIdMy = getAttr("accountId");
        Ret ret = service.findCampusOriginalByPage(accountIdMy, createAccountId, page, limit);
        renderJson(ret);
    }

    @ApiOper("创建原创发布")
    public void creatCampusOriginal(
    		@Size(min = 0, max = 200) @ApiPara(value = "title", notes = "标题") String title,
            @Size(max = 500) @ApiPara(value = "content", notes = "内容") String content,
            @JSONArrayString @ApiPara(value = "files", notes = "files[{type:xxx,url:xxx},{type:xxx,url:xxx}]") String files) throws Exception {
    	Integer accountId = getAttr("accountId");
        Integer userType = getAttr("userType");
        Ret ret = service.creatCampusOriginal(accountId, userType, title, content, files);
        renderJson(ret);
    }

    @ApiOper("删除原创发布")
    public void delCampusOriginal(@Size @ApiPara(value = "shareId", notes = "分享Id") Integer shareId) throws Exception {
    	Integer accountId = getAttr("accountId");
        Ret ret = service.delCampusOriginal(accountId, shareId);
        renderJson(ret);
    }
    
    
    
    
    
    @ApiOper("查询教师推荐列表")
    public void findCampusTeacherRecommendByPage(
    		@BooleanV @ApiPara(value = "isMy", notes = "是不是查询我的推荐") Boolean isMy,
    		@ApiPara(value = "createAccountId", notes = "创建人账号id") Integer createAccountId,
    		@ApiPara(value = "recommendAccountId", notes = "推荐人账号id") Integer recommendAccountId,
         	@Size @ApiPara(value = "page", notes = "当前页") Integer page,
         	@Size @ApiPara(value = "limit", notes = "每页大小") Integer limit) throws Exception {
    	Integer accountIdMy = getAttr("accountId");
        Ret ret = service.findCampusTeacherRecommendByPage(accountIdMy, createAccountId, isMy, recommendAccountId, page, limit);
        renderJson(ret);
    }

    @ApiOper("创建教师推荐(老师三星推荐也是走这个接口)")
    public void creatCampusTeacherRecommend(
    		@ApiPara(value = "title", notes = "标题") String title,
            @Size(max = 500) @ApiPara(value = "content", notes = "内容") String content,
            @JSONArrayString @ApiPara(value = "files", notes = "files[{type:xxx,url:xxx},{type:xxx,url:xxx}]") String files,
            @Size @ApiPara(value = "userAccountId", notes = "用户id") Integer userAccountId,
            @Size @ApiPara(value = "taskId",notes = "任务id")Integer taskId,
            @Size(min = 1, max = 4) @ApiPara(value = "taskType", notes = "任务类型1.任务 2.日常劳动 3.职业体验 4.重要他人任务") Integer taskType) throws Exception {
    	Integer accountId = getAttr("accountId");
        Ret ret = service.creatCampusTeacherRecommend(accountId, title, content, files, userAccountId, taskType,taskId);
        renderJson(ret);
    }

    @ApiOper("删除教师推荐")
    public void delCampusTeacherRecommend(@Size @ApiPara(value = "shareId", notes = "分享Id") Integer shareId) throws Exception {
    	Integer accountId = getAttr("accountId");
        Ret ret = service.delCampusTeacherRecommend(accountId, shareId);
        renderJson(ret);
    }
    
    
    
    
    
    
    
    
    @ApiOper("查询第一层评论")
    public void findComments(
    		@Size @ApiPara(value = "shareId", notes = "分享Id") Integer shareId,
    		@Size(min = 2, max = 3)@Size @ApiPara(value = "shareType", notes = "类型 2.教师推荐 3.原创发布") Integer shareType,
    		@Size @ApiPara(value = "page", notes = "当前页") Integer page,
    		@Size @ApiPara(value = "limit", notes = "每页大小") Integer limit) throws Exception {
        Ret ret = service.findComments(shareId, page, limit, shareType);
        renderJson(ret);
    }

    @ApiOper("查询第二层评论")
    public void findSecondComments(
    		@Size @ApiPara(value = "shareId", notes = "分享Id") Integer shareId,
    		@Size @ApiPara(value = "topCommentsId", notes = "评论ID") Integer topCommentsId) throws Exception {
        Ret ret = service.findSecondComments(shareId, topCommentsId);
        renderJson(ret);
    }

    @ApiOper("对分享点赞/取消点赞")
    public void likeCampusShare(
    		@Size @ApiPara(value = "shareId", notes = "分享Id") Integer shareId,
            @Size(min = 2, max = 3) @ApiPara(value = "shareType", notes = "类型 2.教师推荐 3.原创发布") Integer shareType) throws Exception {
    	Integer accountId = getAttr("accountId");
        Ret ret = service.likeCampusShare(accountId, shareId, shareType);
        renderJson(ret);
    }

    @ApiOper("对评论点赞/取消点赞")
    public void likeComments(@Size @ApiPara(value = "commentsId", notes = "评论Id") Integer commentsId) throws Exception {
    	Integer accountId = getAttr("accountId");
        Ret ret = service.likeComments(accountId, commentsId);
        renderJson(ret);
    }

    @ApiOper("发表评论")
    public void addComments(
    		@Size @ApiPara(value = "shareId", notes = "分享Id") Integer shareId,
            @Size(min = 2, max = 3) @ApiPara(value = "shareType", notes = "类型 2.教师推荐 3.原创发布") Integer shareType,
            @Size(min = 1, max = 500) @ApiPara(value = "comment", notes = "评论内容") String comment,
            @ApiPara(value = "commentsId", notes = "评论Id") Integer commentsId,
            @ApiPara(value = "topCommentsId", notes = "顶层评论Id") Integer topCommentsId) throws Exception {
    	Integer accountId = getAttr("accountId");
        Ret ret = service.addComments(accountId, shareId, commentsId, comment, topCommentsId, shareType);
        renderJson(ret);
    }

    @ApiOper("删除评论")
    public void delComments(@Size @ApiPara(value = "commentsId", notes = "评论Id") Integer commentsId) throws Exception {
    	Integer accountId = getAttr("accountId");
        Ret ret = service.delComments(accountId, commentsId);
        renderJson(ret);
    }
    

    
    
    @ApiOper("我的校园中教师推荐和原创发布的分享按钮")
    public void shareContent(
    		@Size @ApiPara(value = "id",notes = "内容id")Integer id,
    		@Size(min = 2, max = 3) @Size @ApiPara(value = "shareType",notes = "类型 2.教师推荐 3.原创发布")Integer shareType)throws Exception{
    	Integer accountId = getAttr("accountId");
        Ret ret = service.shareContent(accountId, id, shareType);
        renderJson(ret);
    }
    
}
